package com.cm.caseManagement.controller;


import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmAdvanceCost;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmAdvanceCostService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 代收代付Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/cost")
public class CmAdvanceCostController extends BaseController
{
    @Autowired
    private ICmAdvanceCostService cmAdvanceCostService;

    /**
     * 查询代收代付列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmAdvanceCost cmAdvanceCost)
    {
        startPage();
        List<CmAdvanceCost> list = cmAdvanceCostService.selectCmAdvanceCostList(cmAdvanceCost);
        return getDataTable(list);
    }

    /**
     * 导出代收代付列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:cost:export')")
    @Log(title = "代收代付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmAdvanceCost cmAdvanceCost)
    {
        List<CmAdvanceCost> list = cmAdvanceCostService.selectCmAdvanceCostList(cmAdvanceCost);
        ExcelUtil<CmAdvanceCost> util = new ExcelUtil<CmAdvanceCost>(CmAdvanceCost.class);
        util.exportExcel(response, list, "代收代付数据");
    }

    /**
     * 获取代收代付详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:cost:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmAdvanceCostService.selectCmAdvanceCostById(id));
    }

    /**
     * 新增代收代付
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:cost:add')")
    @Log(title = "代收代付", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmAdvanceCost cmAdvanceCost)
    {
        return toAjax(cmAdvanceCostService.insertCmAdvanceCost(cmAdvanceCost));
    }

    /**
     * 修改代收代付
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:cost:edit')")
    @Log(title = "代收代付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmAdvanceCost cmAdvanceCost)
    {
        return toAjax(cmAdvanceCostService.updateCmAdvanceCost(cmAdvanceCost));
    }

    /**
     * 删除代收代付
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:cost:remove')")
    @Log(title = "代收代付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmAdvanceCostService.deleteCmAdvanceCostByIds(ids));
    }
}
